
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QTimer>
#include <QStyleFactory>
#include <QAction>
#include "platform/common.h"
#include "ShortCut.h"
#include "ConfigEditor.h"
#include "ConfigData.h"
#include "SystemTrayIcon.h"
#include "FloatButton.h"
#include "translator/BaiduTranslate.h"
#include "translator/BaiduOCR.h"


static int init()
{
    QDir::home().mkpath(Platform::dataDir.absolutePath());
    ConfigData::instance().m_filePath = Platform::dataDir.absoluteFilePath("Config.dat");
    ConfigData::instance().readFromFile();
    return 0;
}


int main(int argc, char *argv[])
{
    QApplication::setAttribute(Qt::AA_DisableHighDpiScaling); // deepin v20正式版中要关闭HighDPI缩放，使用物理坐标。
    QApplication::setQuitOnLastWindowClosed(false); // 关闭窗口时，程序不退出
    QApplication a(argc, argv);
    // QApplication::setStyle(QStyleFactory::create("Fusion"));

    init();

    ShortCut shortcut(&ConfigData::instance());


    QObject::connect(&Platform::monitor(), QOverload<int>::of(&IMonitor::keyPressed), &shortcut, [&shortcut](int code){
        shortcut.pressed(Platform::toQtKey(code));
    });

    QObject::connect(&Platform::monitor(), QOverload<int>::of(&IMonitor::keyReleased), &shortcut, [&shortcut](int code){
        shortcut.released(Platform::toQtKey(code));
    });



    QObject::connect(&Platform::monitor(), &IMonitor::contentPicked, &a, [](QString name, QString content){
       qInfo() << name << content;
    });



    //Platform::monitor().screenShot();

    //QTimer::singleShot(5000, &a, &QCoreApplication::quit);

    ConfigData::instance().updateURL->set("qqwr");
    // config().translate->searchBarShortcut->set(true, QKeySequence(Qt::ControlModifier + Qt::Key_A));

    SystemTrayIcon tray;

    FloatButton floatButton;


    tray.show();


    return a.exec();
}
